<script>

import * as echarts from 'echarts';
// import $ from 'jquery'
export default {
  name: 'VisualizationSeven',
  data() {
    return{

    }
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      this.$axios.get('/api/vis/data7', {}).then(res => {
        if (res.data.code === 20041) {
          let data1 = [];
          let data2 = [];
          for (let i = 0; i < 10; i++) {
            data1.push(
                res.data.data[i].param1
            );
            data2.push(
                res.data.data[i].param2
            );
          }
          this.init(data1, data2);
        }
      }).catch(error => {
        this.open4(error);
      });
    },
    open4(msg) {
      this.$notify.error({
        title: msg,
        message: '这是一条错误的提示消息'
      });
    },
    init(data1, data2) {
      var chartDom = document.getElementById('main7');
      var myChart = echarts.init(chartDom);
      var option;

      option = {
        title: {
          text: '价格Top10商品'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          },
          valueFormatter: (value) => value + '元' //改变显示文字
        },
        legend: {},
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            name: "商品",
            type: 'value',
            axisLine: {
              show: true,
              lineStyle: {
                width: 1
              }
            },
            show: true,
            offset:20,
            maxInterval:6475912  //值坐标最大的数值间隔 最小同样min
          }
        ],
        yAxis: [
          {
            name: "商品总售价",
            type: 'category',
            data: data1,
            axisLine: {
              show: true,
              lineStyle: {
                width: 2
              }
            },
            axisLabel: {
              margin: 20
            },
            nameGap: 20,
            position: 'left',
            offset:20,
          }
        ],
        series: [
          {
            // name: '2012',
            type: 'bar',
            // xAxisIndex:1,
            data: data2
          }
        ]
      };

      option && myChart.setOption(option);

    }
  }

}
</script>

<template>
  <div id="main7"></div>
</template>

<style scoped>
#main7 {
  width: 100%;
  height: 100%;
}
</style>